<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='./vue.js'></script>
</head>

<body>
    <div id='app'>
        <h1> {{count}} </h1>
        <button @click="getCell">点击查看子组件</button>

        <cell ref="cell"></cell>
    </div>
</body>
<script>


    const cell = {
        template: `<h1>
                {{ msg }}

                <button @click="getApp">点击查看父组件</button>
            </h1>`,
        // 用来限制父组件通过 ref 属性来获取当前组件实例
        expose: ['msg'],
        data() {
            return {
                msg: '锄禾日当午'
            }
        },
        methods: {
            getApp() {
                // this.$parent 找到父组件，且可以修改父组件
                // 我们这里不是子组件改父组件，而是找到父组件，有父组件自己去改
                // console.log(this.$parent);
                // this.$parent.count = 111


                // this.$root 是用来获取根组件用的
                console.log(this.$root);

            }
        }
    }


    const app = {
        data() {
            return {
                count: 100
            }
        },
        methods: {
            getCell() {
                console.log(this.$refs.cell);
            }
        },
        components: {
            cell
        }
    }
    const vm = Vue.createApp(app).mount('#app')
</script>

</html>